<!DOCTYPE html>

<html>
<head>
  <title>main.js</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="../docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
    <ul class="sections">
        
          <li id="title">
              <div class="annotation">
                  <h1>main.js</h1>
              </div>
          </li>
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              <p>This file contains code to start up pages on the site, and other code that
is not directly related to parsing and display of regular expressions.</p>
<p>Since the code in this is executed immediately, it is all but impossible to
test. Therefore, this code is kept as simple as possible to reduce the need
to run it through automated tests.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
<span class="hljs-keyword">import</span> util <span class="hljs-keyword">from</span> <span class="hljs-string">'./util.js'</span>;
<span class="hljs-keyword">import</span> Regexper <span class="hljs-keyword">from</span> <span class="hljs-string">'./regexper.js'</span>;
<span class="hljs-keyword">import</span> Parser <span class="hljs-keyword">from</span> <span class="hljs-string">'./parser/javascript.js'</span>;
<span class="hljs-keyword">import</span> _ <span class="hljs-keyword">from</span> <span class="hljs-string">'lodash'</span>;

(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{</pre></div></div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <p>Initialize the main page of the site. Functionality is kept in the
<a href="./regexper.html">Regexper class</a>.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="hljs-keyword">if</span> (<span class="hljs-built_in">document</span>.body.querySelector(<span class="hljs-string">'#content .application'</span>)) {
    <span class="hljs-keyword">let</span> regexper = <span class="hljs-keyword">new</span> Regexper(<span class="hljs-built_in">document</span>.body);

    regexper.detectBuggyHash();
    regexper.bindListeners();

    util.tick().then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
      <span class="hljs-built_in">window</span>.dispatchEvent(util.customEvent(<span class="hljs-string">'hashchange'</span>));
    });
  }</pre></div></div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              <p>Initialize other pages on the site (specifically the documentation page).
Any element with a <code>data-expr</code> attribute will contain a rendering of the
provided regular expression.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  _.each(<span class="hljs-built_in">document</span>.querySelectorAll(<span class="hljs-string">'[data-expr]'</span>), element =&gt; {
    <span class="hljs-keyword">new</span> Parser(element, { <span class="hljs-attr">keepContent</span>: <span class="hljs-literal">true</span> })
      .parse(element.getAttribute(<span class="hljs-string">'data-expr'</span>))
      .then(<span class="hljs-function"><span class="hljs-params">parser</span> =&gt;</span> {
        parser.render();
      })
      .catch(util.exposeError);
  });
}());</pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>
